import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
	state: {
		count: 0, // 购物车总数
		userId: sessionStorage.getItem('userId'),
		isLogin: sessionStorage.getItem('isLogin'),
	},

	mutations: {
		add(state) {
			state.count += 1
		},
		getCount(state, value) {
			state.count = value
		},

		reduceCount(state, num) {
			state.count -= num
		},

		$_setLogin(state, userId) {
			state.isLogin = true
			state.userId = userId
			sessionStorage.setItem('isLogin', true)
			sessionStorage.setItem('userId', userId)
		},
		$_removeStorage(state) {
			state.userId = ''
			state.isLogin = false
			state.count = 0
			sessionStorage.clear()
		},
	},
	actions: {},
	modules: {},
})
